package marker.xml;

import java.io.File;

import marker.xml.metadata.InfoBean;
import marker.xml.metadata.MsgBean;
import marker.xml.metadata.ProtocolBean;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

public class XmlParser {
	private final Serializer serializer = new Persister();

	public InfoBean parseInfoBean(File file) throws Exception {
		try{
			InfoBean infoBean = serializer.read(InfoBean.class, file);
			return infoBean;
		}catch(Exception e){
			throw new Exception(file+"解析出错",e);
		}
		
	}

	public MsgBean parseMsgBean(File file) throws Exception {
		ProtocolBean protocolBean = serializer.read(ProtocolBean.class, file);
		MsgBean bean = protocolBean.getRequestBean();
		if (bean != null) {
			bean.setRequest(true);
			bean.initReturnMsg(protocolBean.getResponses());
		} else {
			bean = protocolBean.getResponseBean();
		}
		return bean;
	}

	public static void main(String[] args) throws Exception {
		String path = "D://working//game_msg//协议文档//bean//Test.xml";
		Serializer serializer = new Persister();
		InfoBean infoBean = serializer.read(InfoBean.class, new File(path));
	}
}
